<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Docker 命令大全 | 小鹏杂谈</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/favicon.ico">
    <meta name="description" content="小鹏杂谈">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=no">
    
    <link rel="preload" href="/assets/css/0.styles.8516fda1.css" as="style"><link rel="preload" href="/assets/js/app.b9ccfc55.js" as="script"><link rel="preload" href="/assets/js/4.8390fbcb.js" as="script"><link rel="preload" href="/assets/js/1.3334f995.js" as="script"><link rel="preload" href="/assets/js/33.2dcc611d.js" as="script"><link rel="prefetch" href="/assets/js/10.8eb4e356.js"><link rel="prefetch" href="/assets/js/11.31befa4c.js"><link rel="prefetch" href="/assets/js/12.da37eb75.js"><link rel="prefetch" href="/assets/js/13.b24ba73c.js"><link rel="prefetch" href="/assets/js/14.3bbed283.js"><link rel="prefetch" href="/assets/js/15.fac60f8d.js"><link rel="prefetch" href="/assets/js/16.b75d2036.js"><link rel="prefetch" href="/assets/js/17.116317c5.js"><link rel="prefetch" href="/assets/js/18.80fdbeda.js"><link rel="prefetch" href="/assets/js/19.459fc46f.js"><link rel="prefetch" href="/assets/js/20.452f30f9.js"><link rel="prefetch" href="/assets/js/21.99f641dc.js"><link rel="prefetch" href="/assets/js/22.081dc33b.js"><link rel="prefetch" href="/assets/js/23.d3455a59.js"><link rel="prefetch" href="/assets/js/24.8f5d39e0.js"><link rel="prefetch" href="/assets/js/25.c3dc47fb.js"><link rel="prefetch" href="/assets/js/26.d93b5cf2.js"><link rel="prefetch" href="/assets/js/27.6d2089a5.js"><link rel="prefetch" href="/assets/js/28.57336847.js"><link rel="prefetch" href="/assets/js/29.903b5e06.js"><link rel="prefetch" href="/assets/js/3.32100170.js"><link rel="prefetch" href="/assets/js/30.274666a3.js"><link rel="prefetch" href="/assets/js/31.fa9bd0f8.js"><link rel="prefetch" href="/assets/js/32.20179720.js"><link rel="prefetch" href="/assets/js/34.ba79122c.js"><link rel="prefetch" href="/assets/js/35.bcd9298f.js"><link rel="prefetch" href="/assets/js/36.bf6245d9.js"><link rel="prefetch" href="/assets/js/37.734eb893.js"><link rel="prefetch" href="/assets/js/38.26999070.js"><link rel="prefetch" href="/assets/js/39.cc1f016d.js"><link rel="prefetch" href="/assets/js/40.da84c263.js"><link rel="prefetch" href="/assets/js/41.a96b8efa.js"><link rel="prefetch" href="/assets/js/42.d586cccb.js"><link rel="prefetch" href="/assets/js/43.69bb61aa.js"><link rel="prefetch" href="/assets/js/44.3be5a840.js"><link rel="prefetch" href="/assets/js/45.208a3bc3.js"><link rel="prefetch" href="/assets/js/46.2d6cacad.js"><link rel="prefetch" href="/assets/js/47.5add378a.js"><link rel="prefetch" href="/assets/js/48.587139cc.js"><link rel="prefetch" href="/assets/js/49.57f7c25a.js"><link rel="prefetch" href="/assets/js/5.ff1e84d1.js"><link rel="prefetch" href="/assets/js/50.efde6e4a.js"><link rel="prefetch" href="/assets/js/51.c9447e5f.js"><link rel="prefetch" href="/assets/js/52.57a51c35.js"><link rel="prefetch" href="/assets/js/53.4be0f240.js"><link rel="prefetch" href="/assets/js/54.8dabd349.js"><link rel="prefetch" href="/assets/js/55.3b8ae0e4.js"><link rel="prefetch" href="/assets/js/56.07e830b2.js"><link rel="prefetch" href="/assets/js/57.8c0dbdcc.js"><link rel="prefetch" href="/assets/js/58.63387df6.js"><link rel="prefetch" href="/assets/js/59.959bb8c8.js"><link rel="prefetch" href="/assets/js/6.56a2b5cd.js"><link rel="prefetch" href="/assets/js/60.1041d86f.js"><link rel="prefetch" href="/assets/js/61.f58e6c18.js"><link rel="prefetch" href="/assets/js/62.a1a460c7.js"><link rel="prefetch" href="/assets/js/63.6c611c7d.js"><link rel="prefetch" href="/assets/js/64.6711119c.js"><link rel="prefetch" href="/assets/js/65.4655c3b1.js"><link rel="prefetch" href="/assets/js/66.e5dfe864.js"><link rel="prefetch" href="/assets/js/67.37515de0.js"><link rel="prefetch" href="/assets/js/68.0c8ba92d.js"><link rel="prefetch" href="/assets/js/69.52121d38.js"><link rel="prefetch" href="/assets/js/7.6f143d9f.js"><link rel="prefetch" href="/assets/js/70.1ab4d6a1.js"><link rel="prefetch" href="/assets/js/71.dc99dd1d.js"><link rel="prefetch" href="/assets/js/72.02e21e52.js"><link rel="prefetch" href="/assets/js/73.21efc121.js"><link rel="prefetch" href="/assets/js/74.649f4e1d.js"><link rel="prefetch" href="/assets/js/75.331c13e7.js"><link rel="prefetch" href="/assets/js/76.a94b5ff0.js"><link rel="prefetch" href="/assets/js/8.d4d40f2a.js"><link rel="prefetch" href="/assets/js/9.1b8824e7.js">
    <link rel="stylesheet" href="/assets/css/0.styles.8516fda1.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container no-sidebar" data-v-1156296a><div data-v-1156296a><div id="loader-wrapper" class="loading-wrapper" data-v-d48f4d20 data-v-1156296a data-v-1156296a><div class="loader-main" data-v-d48f4d20><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div><div data-v-d48f4d20></div></div> <!----> <!----></div> <div class="password-shadow password-wrapper-out" style="display:none;" data-v-4e82dffc data-v-1156296a data-v-1156296a><h3 class="title" data-v-4e82dffc data-v-4e82dffc>小鹏杂谈</h3> <p class="description" data-v-4e82dffc data-v-4e82dffc>小鹏杂谈</p> <label id="box" class="inputBox" data-v-4e82dffc data-v-4e82dffc><input type="password" value="" data-v-4e82dffc> <span data-v-4e82dffc>Konck! Knock!</span> <button data-v-4e82dffc>OK</button></label> <div class="footer" data-v-4e82dffc data-v-4e82dffc><span data-v-4e82dffc><i class="iconfont reco-theme" data-v-4e82dffc></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-4e82dffc>vuePress-theme-reco</a></span> <span data-v-4e82dffc><i class="iconfont reco-copyright" data-v-4e82dffc></i> <a data-v-4e82dffc><span data-v-4e82dffc>lzpeng723</span>
            
          <span data-v-4e82dffc>2021 - </span>
          2022
        </a></span></div></div> <div class="hide" data-v-1156296a><header class="navbar" data-v-1156296a><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><img src="/logo.png" alt="小鹏杂谈" class="logo"> <span class="site-name">小鹏杂谈</span></a> <div class="links"><div class="color-picker"><a class="color-button"><i class="iconfont reco-color"></i></a> <div class="color-picker-menu" style="display:none;"><div class="mode-options"><h4 class="title">Choose mode</h4> <ul class="color-mode-options"><li class="dark">dark</li><li class="auto active">auto</li><li class="light">light</li></ul></div></div></div> <div class="search-box"><i class="iconfont reco-search"></i> <input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/运维/" class="nav-link"><i class="undefined"></i>
  运维
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发/" class="nav-link"><i class="undefined"></i>
  开发
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/软件/" class="nav-link"><i class="undefined"></i>
  软件
</a></li><li class="dropdown-item"><!----> <a href="/categories/文档/" class="nav-link"><i class="undefined"></i>
  文档
</a></li><li class="dropdown-item"><!----> <a href="/categories/数据库/" class="nav-link"><i class="undefined"></i>
  数据库
</a></li><li class="dropdown-item"><!----> <a href="/categories/Node.js/" class="nav-link"><i class="undefined"></i>
  Node.js
</a></li><li class="dropdown-item"><!----> <a href="/categories/游戏/" class="nav-link"><i class="undefined"></i>
  游戏
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/minimal-boot/" class="nav-link"><i class="undefined"></i>
  minimal-boot
</a></li><li class="dropdown-item"><!----> <a href="/docs/minimal-cloud/" class="nav-link"><i class="undefined"></i>
  minimal-cloud
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系方式
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://www.zhihu.com/people/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-zhihu"></i>
  知乎
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask" data-v-1156296a></div> <aside class="sidebar" data-v-1156296a><div class="personal-info-wrapper" data-v-828910c6 data-v-1156296a><img src="/avatar.jpg" alt="author-avatar" class="personal-img" data-v-828910c6> <h3 class="name" data-v-828910c6>
    lzpeng723
  </h3> <div class="num" data-v-828910c6><div data-v-828910c6><h3 data-v-828910c6>66</h3> <h6 data-v-828910c6>Articles</h6></div> <div data-v-828910c6><h3 data-v-828910c6>19</h3> <h6 data-v-828910c6>Tags</h6></div></div> <ul class="social-links" data-v-828910c6></ul> <hr data-v-828910c6></div> <nav class="nav-links"><div class="nav-item"><a href="/" class="nav-link"><i class="iconfont reco-home"></i>
  首页
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-category"></i>
      分类
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/categories/运维/" class="nav-link"><i class="undefined"></i>
  运维
</a></li><li class="dropdown-item"><!----> <a href="/categories/开发/" class="nav-link"><i class="undefined"></i>
  开发
</a></li><li class="dropdown-item"><!----> <a href="/categories/后端/" class="nav-link"><i class="undefined"></i>
  后端
</a></li><li class="dropdown-item"><!----> <a href="/categories/前端/" class="nav-link"><i class="undefined"></i>
  前端
</a></li><li class="dropdown-item"><!----> <a href="/categories/软件/" class="nav-link"><i class="undefined"></i>
  软件
</a></li><li class="dropdown-item"><!----> <a href="/categories/文档/" class="nav-link"><i class="undefined"></i>
  文档
</a></li><li class="dropdown-item"><!----> <a href="/categories/数据库/" class="nav-link"><i class="undefined"></i>
  数据库
</a></li><li class="dropdown-item"><!----> <a href="/categories/Node.js/" class="nav-link"><i class="undefined"></i>
  Node.js
</a></li><li class="dropdown-item"><!----> <a href="/categories/游戏/" class="nav-link"><i class="undefined"></i>
  游戏
</a></li></ul></div></div><div class="nav-item"><a href="/tag/" class="nav-link"><i class="iconfont reco-tag"></i>
  标签
</a></div><div class="nav-item"><a href="/timeline/" class="nav-link"><i class="iconfont reco-date"></i>
  时间线
</a></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      文档
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/docs/minimal-boot/" class="nav-link"><i class="undefined"></i>
  minimal-boot
</a></li><li class="dropdown-item"><!----> <a href="/docs/minimal-cloud/" class="nav-link"><i class="undefined"></i>
  minimal-cloud
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><a class="dropdown-title"><span class="title"><i class="iconfont reco-message"></i>
      联系方式
    </span> <span class="arrow right"></span></a> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-github"></i>
  GitHub
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-mayun"></i>
  Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://www.zhihu.com/people/lzpeng723" target="_blank" rel="noopener noreferrer" class="nav-link external"><i class="iconfont reco-zhihu"></i>
  知乎
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav> <!----> </aside> <div class="password-shadow password-wrapper-in" style="display:none;" data-v-4e82dffc data-v-1156296a><h3 class="title" data-v-4e82dffc data-v-4e82dffc>Docker 命令大全</h3> <!----> <label id="box" class="inputBox" data-v-4e82dffc data-v-4e82dffc><input type="password" value="" data-v-4e82dffc> <span data-v-4e82dffc>Konck! Knock!</span> <button data-v-4e82dffc>OK</button></label> <div class="footer" data-v-4e82dffc data-v-4e82dffc><span data-v-4e82dffc><i class="iconfont reco-theme" data-v-4e82dffc></i> <a target="blank" href="https://vuepress-theme-reco.recoluan.com" data-v-4e82dffc>vuePress-theme-reco</a></span> <span data-v-4e82dffc><i class="iconfont reco-copyright" data-v-4e82dffc></i> <a data-v-4e82dffc><span data-v-4e82dffc>lzpeng723</span>
            
          <span data-v-4e82dffc>2021 - </span>
          2022
        </a></span></div></div> <div data-v-1156296a><main class="page"><section><div class="page-title"><h1 class="title">Docker 命令大全</h1> <div data-v-1ff7123e><i class="iconfont reco-account" data-v-1ff7123e><span data-v-1ff7123e>lzpeng723</span></i> <i class="iconfont reco-date" data-v-1ff7123e><span data-v-1ff7123e>9/25/2021</span></i> <!----> <i class="tags iconfont reco-tag" data-v-1ff7123e><span class="tag-item" data-v-1ff7123e>Docker</span></i></div></div> <div class="theme-reco-content content__default"><h1 id="docker-命令大全"><a href="#docker-命令大全" class="header-anchor">#</a> Docker 命令大全</h1> <h2 id="容器生命周期管理"><a href="#容器生命周期管理" class="header-anchor">#</a> 容器生命周期管理</h2> <h3 id="run"><a href="#run" class="header-anchor">#</a> run</h3> <p>docker run ：创建一个新的容器并运行一个命令</p> <h4 id="语法"><a href="#语法" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明"><a href="#options说明" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-a stdin: 指定标准输入输出内容类型，可选 STDIN/STDOUT/STDERR 三项；</li> <li>-d: 后台运行容器，并返回容器ID；</li> <li>-i: 以交互模式运行容器，通常与 -t 同时使用；</li> <li>-P: 随机端口映射，容器内部端口随机映射到主机的端口</li> <li>-p: 指定端口映射，格式为：主机(宿主)端口:容器端口</li> <li>-t: 为容器重新分配一个伪输入终端，通常与 -i 同时使用；</li> <li>--name : 为容器指定一个名称；</li> <li>--dns 8.8.8.8: 指定容器使用的DNS服务器，默认和宿主一致；</li> <li>--dns-search example.com: 指定容器DNS搜索域名，默认和宿主一致；</li> <li>-h &quot;mars&quot;: 指定容器的hostname；</li> <li>-e username=&quot;ritchie&quot;: 设置环境变量；</li> <li>--env-file=[]: 从指定文件读入环境变量；</li> <li>--cpuset=&quot;0-2&quot; or --cpuset=&quot;0,1,2&quot;: 绑定容器到指定CPU运行；</li> <li>-m :设置容器使用内存最大值；</li> <li>--net=&quot;bridge&quot;: 指定容器的网络连接类型，支持 bridge/host/none/container: 四种类型；</li> <li>--link=[]: 添加链接到另一个容器；</li> <li>--expose=[]: 开放一个端口或一组端口；</li> <li>--volume , -v: 绑定一个卷</li></ul> <h4 id="实例"><a href="#实例" class="header-anchor">#</a> 实例</h4> <p>使用docker镜像nginx:latest以后台模式启动一个容器,并将容器命名为mynginx。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker run --name mynginx -d nginx:latest
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>使用镜像nginx:latest以后台模式启动一个容器,并将容器的80端口映射到主机随机端口。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker run -P -d nginx:latest
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>使用镜像 nginx:latest，以后台模式启动一个容器,将容器的 80 端口映射到主机的 80 端口,主机的目录 /www/data 映射到容器的 /data。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker run -p 80:80 -v /www/data:/data -d nginx:latest
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>绑定容器的 8080 端口，并将其映射到本地主机 127.0.0.1 的 80 端口上。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker run -p 127.0.0.1:80:8080/tcp ubuntu bash
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>使用镜像nginx:latest以交互模式启动一个容器,在容器内执行/bin/bash命令。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker run -it nginx:latest /bin/bash
root@b8573233d675:/# 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="start-stop-restart"><a href="#start-stop-restart" class="header-anchor">#</a> start/stop/restart</h3> <p>docker start :启动一个或多个已经被停止的容器
docker stop :停止一个运行中的容器
docker restart :重启容器</p> <h4 id="语法-2"><a href="#语法-2" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker start [OPTIONS] CONTAINER [CONTAINER...]
docker stop [OPTIONS] CONTAINER [CONTAINER...]
docker restart [OPTIONS] CONTAINER [CONTAINER...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h4 id="实例-2"><a href="#实例-2" class="header-anchor">#</a> 实例</h4> <p>启动已被停止的容器 mynginx</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker start mynginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>停止运行中的容器 mynginx</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker stop mynginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>重启容器 mynginx</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker restart mynginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>停止所有容器</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker stop $(docker ps -q)
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="kill"><a href="#kill" class="header-anchor">#</a> kill</h3> <p>docker kill :杀掉一个运行中的容器。</p> <h4 id="语法-3"><a href="#语法-3" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker kill [OPTIONS] CONTAINER [CONTAINER...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-2"><a href="#options说明-2" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-s :向容器发送一个信号</li></ul> <h4 id="实例-3"><a href="#实例-3" class="header-anchor">#</a> 实例</h4> <p>杀掉运行中的容器mynginx</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker kill -s KILL mynginx
mynginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>杀死所有正在运行的容器</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker kill $(docker ps -a -q)
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="rm"><a href="#rm" class="header-anchor">#</a> rm</h3> <p>docker rm ：删除一个或多个容器。</p> <h4 id="语法-4"><a href="#语法-4" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rm [OPTIONS] CONTAINER [CONTAINER...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-3"><a href="#options说明-3" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-f :通过 SIGKILL 信号强制删除一个运行中的容器。</li> <li>-l :移除容器间的网络连接，而非容器本身。</li> <li>-v :删除与容器关联的卷。</li></ul> <h4 id="实例-4"><a href="#实例-4" class="header-anchor">#</a> 实例</h4> <p>强制删除容器 db01、db02：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rm -f db01 db02
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>移除容器 nginx01 对容器 db01 的连接，连接名 db：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rm -l db 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>删除容器 nginx01, 并删除容器挂载的数据卷：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rm -v nginx01
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>删除所有已经停止的容器：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rm $(docker ps -a -q)
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="pause-unpause"><a href="#pause-unpause" class="header-anchor">#</a> pause/unpause</h3> <p>docker pause :暂停容器中所有的进程。
docker unpause :恢复容器中所有的进程。</p> <h4 id="语法-5"><a href="#语法-5" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker pause CONTAINER [CONTAINER...]
docker unpause CONTAINER [CONTAINER...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h4 id="实例-5"><a href="#实例-5" class="header-anchor">#</a> 实例</h4> <p>暂停数据库容器db01提供服务。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker pause db01
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>恢复数据库容器 db01 提供服务。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker unpause db01
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="create"><a href="#create" class="header-anchor">#</a> create</h3> <p>docker create ：创建一个新的容器但不启动它
用法同 <a href="#run">docker run</a></p> <h4 id="语法-6"><a href="#语法-6" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker create [OPTIONS] IMAGE [COMMAND] [ARG...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>语法同 <a href="#run">docker run</a></p> <h4 id="实例-6"><a href="#实例-6" class="header-anchor">#</a> 实例</h4> <p>使用docker镜像nginx:latest创建一个容器,并将容器命名为mynginx</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker create  --name mynginx  nginx:latest      
09b93464c2f75b7b69f83d56a9cfc23ceb50a48a9db7652ee4c27e3e2cb1961f
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="exec"><a href="#exec" class="header-anchor">#</a> exec</h3> <p>docker exec ：在运行的容器中执行命令</p> <h4 id="语法-7"><a href="#语法-7" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-4"><a href="#options说明-4" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-d :分离模式: 在后台运行</li> <li>-i :即使没有附加也保持STDIN 打开</li> <li>-t :分配一个伪终端</li></ul> <h4 id="实例-7"><a href="#实例-7" class="header-anchor">#</a> 实例</h4> <p>在容器 mynginx 中以交互模式执行容器内 /root/my.sh 脚本:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker exec -it mynginx /bin/sh /root/my.sh
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>在容器 mynginx 中开启一个交互模式的终端:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker exec -i -t  mynginx /bin/bash
root@b1a0703e41e7:/#
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><p>也可以通过 <code>docker ps -a</code> 命令查看已经在运行的容器，然后使用容器 ID 进入容器。
查看已经在运行的容器 ID：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker ps -a 

9df70f9a0714        openjdk             &quot;/usercode/script.sh…&quot; 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>第一列的 <code>9df70f9a0714</code> 就是容器 ID。
通过 exec 命令对指定的容器执行 bash:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker exec -it 9df70f9a0714 /bin/bash
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="容器操作"><a href="#容器操作" class="header-anchor">#</a> 容器操作</h2> <h3 id="ps"><a href="#ps" class="header-anchor">#</a> ps</h3> <p>docker ps : 列出容器</p> <h4 id="语法-8"><a href="#语法-8" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker ps [OPTIONS]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-5"><a href="#options说明-5" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-a :显示所有的容器，包括未运行的。</li> <li>-f :根据条件过滤显示的内容。</li> <li>--format :指定返回值的模板文件。</li> <li>-l :显示最近创建的容器。</li> <li>-n :列出最近创建的n个容器。</li> <li>--no-trunc :不截断输出。</li> <li>-q :静默模式，只显示容器编号。</li> <li>-s :显示总的文件大小。</li></ul> <h4 id="实例-8"><a href="#实例-8" class="header-anchor">#</a> 实例</h4> <p>列出所有在运行的容器信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker ps
CONTAINER ID   IMAGE          COMMAND                ...  PORTS                    NAMES
09b93464c2f7   nginx:latest   &quot;nginx -g 'daemon off&quot; ...  80/tcp, 443/tcp          mynginx
96f7f14e99ab   mysql:5.6      &quot;docker-entrypoint.sh&quot; ...  0.0.0.0:3306-&gt;3306/tcp   mymysql
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>输出详情介绍：</p> <ul><li>CONTAINER ID: 容器 ID。</li> <li>IMAGE: 使用的镜像。</li> <li>COMMAND: 启动容器时运行的命令。</li> <li>CREATED: 容器的创建时间。</li> <li>STATUS: 容器状态。
状态有7种：
<ul><li>created（已创建）</li> <li>restarting（重启中）</li> <li>running（运行中）</li> <li>removing（迁移中）</li> <li>paused（暂停）</li> <li>exited（停止）</li> <li>dead（死亡）</li></ul></li> <li>PORTS: 容器的端口信息和使用的连接类型（tcp\udp）。</li> <li>NAMES: 自动分配的容器名称</li></ul> <p>列出最近创建的5个容器信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker ps -n 5
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>列出所有创建的容器ID。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker ps -a -q
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>根据标签过滤</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker run -d --name=test-nginx --label color=blue nginx
docker ps --filter &quot;label=color&quot;
docker ps --filter &quot;label=color=blue&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>根据名称过滤</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker ps --filter&quot;name=test-nginx&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>根据状态过滤</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>$ docker ps -a --filter 'exited=0'
$ docker ps --filter status=running
$ docker ps --filter status=paused
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>根据镜像过滤</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>#镜像名称
docker ps --filter ancestor=nginx
#镜像ID
docker ps --filter ancestor=d0e008c6cf02
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>根据启动顺序过滤</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker ps -f before=9c3527ed70ce
docker ps -f since=6e63f6ff38b0
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="inspect"><a href="#inspect" class="header-anchor">#</a> inspect</h3> <p>docker inspect : 获取容器/镜像的元数据。</p> <h4 id="语法-9"><a href="#语法-9" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker inspect [OPTIONS] NAME|ID [NAME|ID...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-6"><a href="#options说明-6" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-f :指定返回值的模板文件。</li> <li>-s :显示总的文件大小。</li> <li>--type :为指定类型返回JSON。</li></ul> <h4 id="实例-9"><a href="#实例-9" class="header-anchor">#</a> 实例</h4> <p>获取镜像mysql:5.6的元信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker inspect mysql:5.6
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>获取正在运行的容器mymysql的 IP。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mymysql
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="top"><a href="#top" class="header-anchor">#</a> top</h3> <p>docker top :查看容器中运行的进程信息，支持 ps 命令参数。</p> <h4 id="语法-10"><a href="#语法-10" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker top [OPTIONS] CONTAINER [ps OPTIONS]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>容器运行时不一定有<code>/bin/bash</code>终端来交互执行<code>top</code>命令，而且容器还不一定有<code>top</code>命令，可以使用<code>docker top</code>来实现查看container中正在运行的进程。</p> <h4 id="实例-10"><a href="#实例-10" class="header-anchor">#</a> 实例</h4> <p>查看容器mymysql的进程信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker top mymysql
UID    PID    PPID    C      STIME   TTY  TIME       CMD
999    40347  40331   18     00:58   ?    00:00:02   mysqld
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>查看所有运行容器的进程信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>for i in  `docker ps |grep Up|awk '{print $1}'`;do echo \ &amp;&amp;docker top $i; done
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="attach"><a href="#attach" class="header-anchor">#</a> attach</h3> <p>docker attach :连接到正在运行中的容器。</p> <h4 id="语法-11"><a href="#语法-11" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker attach [OPTIONS] CONTAINER
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>要attach上去的容器必须正在运行，可以同时连接上同一个container来共享屏幕（与screen命令的attach类似）。
官方文档中说attach后可以通过CTRL-C来detach，但实际上经过我的测试，如果container当前在运行bash，CTRL-C自然是当前行的输入，没有退出；如果container当前正在前台运行进程，如输出nginx的access.log日志，CTRL-C不仅会导致退出容器，而且还stop了。这不是我们想要的，detach的意思按理应该是脱离容器终端，但容器依然运行。好在attach是可以带上<code>--sig-proxy=false</code>来确保CTRL-D或CTRL-C不会关闭容器。</p> <h4 id="实例-11"><a href="#实例-11" class="header-anchor">#</a> 实例</h4> <p>容器mynginx将访问日志指到标准输出，连接到容器查看访问信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker attach --sig-proxy=false mynginx
192.168.239.1 - - [10/Jul/2016:16:54:26 +0000] &quot;GET / HTTP/1.1&quot; 304 0 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.93 Safari/537.36&quot; &quot;-&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="events"><a href="#events" class="header-anchor">#</a> events</h3> <p>docker events : 从服务器获取实时事件</p> <h4 id="语法-12"><a href="#语法-12" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker events [OPTIONS]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-7"><a href="#options说明-7" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-f ：根据条件过滤事件；</li> <li>--since ：从指定的时间戳后显示所有事件;</li> <li>--until ：流水时间显示到指定的时间为止；</li></ul> <h4 id="实例-12"><a href="#实例-12" class="header-anchor">#</a> 实例</h4> <p>显示docker 2016年7月1日后的所有事件。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker events  --since=&quot;1467302400&quot;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>显示docker 镜像为mysql:5.6 2016年7月1日后的相关事件。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker events -f &quot;image&quot;=&quot;mysql:5.6&quot; --since=&quot;1467302400&quot; 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>如果指定的时间是到秒级的，需要将时间转成时间戳。如果时间为日期的话，可以直接使用，如<code>--since=&quot;2016-07-01&quot;</code>。</p> <h3 id="logs"><a href="#logs" class="header-anchor">#</a> logs</h3> <p>docker logs : 获取容器的日志</p> <h4 id="语法-13"><a href="#语法-13" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker logs [OPTIONS] CONTAINER
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-8"><a href="#options说明-8" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-f : 跟踪日志输出</li> <li>--since :显示某个开始时间的所有日志</li> <li>-t : 显示时间戳</li> <li>--tail :仅列出最新N条容器日志</li></ul> <h4 id="实例-13"><a href="#实例-13" class="header-anchor">#</a> 实例</h4> <p>跟踪查看容器mynginx的日志输出。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker logs -f mynginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>查看容器mynginx从2016年7月1日后的最新10条日志。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker logs --since=&quot;2016-07-01&quot; --tail=10 mynginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="wait"><a href="#wait" class="header-anchor">#</a> wait</h3> <p>docker wait : 阻塞运行直到容器停止，然后打印出它的退出代码。</p> <h4 id="语法-14"><a href="#语法-14" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker wait [OPTIONS] CONTAINER [CONTAINER...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="实例-14"><a href="#实例-14" class="header-anchor">#</a> 实例</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker wait CONTAINER
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="export"><a href="#export" class="header-anchor">#</a> export</h3> <p>docker export :将文件系统作为一个tar归档文件导出到STDOUT。</p> <h4 id="语法-15"><a href="#语法-15" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker export [OPTIONS] CONTAINER
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-9"><a href="#options说明-9" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-o :将输入内容写到文件。</li></ul> <h4 id="实例-15"><a href="#实例-15" class="header-anchor">#</a> 实例</h4> <p>将id为a404c6c174a2的容器按日期保存为tar文件。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker export a404c6c174a2 &gt; mysql-`date +%Y%m%d`.tar
docker export -o mysql-`date +%Y%m%d`.tar a404c6c174a2
ls mysql-`date +%Y%m%d`.tar
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="port"><a href="#port" class="header-anchor">#</a> port</h3> <p>docker port :列出指定的容器的端口映射，或者查找将PRIVATE_PORT NAT到面向公众的端口。</p> <h4 id="语法-16"><a href="#语法-16" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker port [OPTIONS] CONTAINER [PRIVATE_PORT[/PROTO]]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="实例-16"><a href="#实例-16" class="header-anchor">#</a> 实例</h4> <p>查看容器mynginx的端口映射情况。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker port mynginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="容器rootfs命令"><a href="#容器rootfs命令" class="header-anchor">#</a> 容器rootfs命令</h2> <h3 id="commit"><a href="#commit" class="header-anchor">#</a> commit</h3> <p>docker commit :从容器创建一个新的镜像。</p> <h4 id="语法-17"><a href="#语法-17" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-10"><a href="#options说明-10" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-a :提交的镜像作者；</li> <li>-c :使用Dockerfile指令来创建镜像；</li> <li>-m :提交时的说明文字；</li> <li>-p :在commit时，将容器暂停。</li></ul> <h4 id="实例-17"><a href="#实例-17" class="header-anchor">#</a> 实例</h4> <p>将容器a404c6c174a2 保存为新的镜像,并添加提交人信息和说明信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker commit -a &quot;lzpeng723&quot; -m &quot;temp data&quot; a404c6c174a2  mymysql:v1
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="cp"><a href="#cp" class="header-anchor">#</a> cp</h3> <p>docker cp :用于容器与主机之间的数据拷贝。</p> <h4 id="语法-18"><a href="#语法-18" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h4 id="options说明-11"><a href="#options说明-11" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-L :保持源目标中的链接</li></ul> <h4 id="实例-18"><a href="#实例-18" class="header-anchor">#</a> 实例</h4> <p>将主机/www/pages目录拷贝到容器96f7f14e99ab的/www目录下。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker cp /www/pages 96f7f14e99ab:/www/
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>将主机/www/pages目录拷贝到容器96f7f14e99ab中，目录重命名为www。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker cp /www/pages 96f7f14e99ab:/www
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>将容器96f7f14e99ab的/www目录拷贝到主机的/tmp目录中。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker cp  96f7f14e99ab:/www /tmp/
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="diff"><a href="#diff" class="header-anchor">#</a> diff</h3> <p>docker diff : 检查容器里文件结构的更改。</p> <h4 id="语法-19"><a href="#语法-19" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker diff [OPTIONS] CONTAINER
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="实例-19"><a href="#实例-19" class="header-anchor">#</a> 实例</h4> <p>查看容器mymysql的文件结构更改。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker diff mymysql
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="镜像仓库"><a href="#镜像仓库" class="header-anchor">#</a> 镜像仓库</h2> <h3 id="login"><a href="#login" class="header-anchor">#</a> login</h3> <p>docker login : 登陆到一个Docker镜像仓库，如果未指定镜像仓库地址，默认为官方仓库 Docker Hub
docker logout : 登出一个Docker镜像仓库，如果未指定镜像仓库地址，默认为官方仓库 Docker Hub</p> <h4 id="语法-20"><a href="#语法-20" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker login [OPTIONS] [SERVER]
docker logout [OPTIONS] [SERVER]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h4 id="options说明-12"><a href="#options说明-12" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-u :登陆的用户名</li> <li>-p :登陆的密码</li></ul> <h4 id="实例-20"><a href="#实例-20" class="header-anchor">#</a> 实例</h4> <p>登陆到Docker Hub</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker login -u 用户名 -p 密码
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>登出Docker Hub</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker logout
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="pull"><a href="#pull" class="header-anchor">#</a> pull</h3> <p>docker pull : 从镜像仓库中拉取或者更新指定镜像</p> <h4 id="语法-21"><a href="#语法-21" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker pull [OPTIONS] NAME[:TAG|@DIGEST]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-13"><a href="#options说明-13" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-a :拉取所有 tagged 镜像</li> <li>--disable-content-trust :忽略镜像的校验,默认开启</li></ul> <h4 id="实例-21"><a href="#实例-21" class="header-anchor">#</a> 实例</h4> <p>从Docker Hub下载java最新版镜像。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker pull java
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>从Docker Hub下载REPOSITORY为java的所有镜像。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker pull -a java
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="push"><a href="#push" class="header-anchor">#</a> push</h3> <p>docker push : 将本地的镜像上传到镜像仓库,要先登陆到镜像仓库</p> <h4 id="语法-22"><a href="#语法-22" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker push [OPTIONS] NAME[:TAG]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-14"><a href="#options说明-14" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>--disable-content-trust :忽略镜像的校验,默认开启</li></ul> <h4 id="实例-22"><a href="#实例-22" class="header-anchor">#</a> 实例</h4> <p>上传本地镜像myapache:v1到镜像仓库中。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker push myapache:v1
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="search"><a href="#search" class="header-anchor">#</a> search</h3> <p>docker search : 从Docker Hub查找镜像</p> <h4 id="语法-23"><a href="#语法-23" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker search [OPTIONS] TERM
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-15"><a href="#options说明-15" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>--automated :只列出 automated build类型的镜像；</li> <li>--no-trunc :显示完整的镜像描述；</li> <li>-f &lt;过滤条件&gt;:列出收藏数不小于指定值的镜像。</li></ul> <h4 id="实例-23"><a href="#实例-23" class="header-anchor">#</a> 实例</h4> <p>从 Docker Hub 查找所有镜像名包含 java，并且收藏数大于 10 的镜像</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker search -f stars=10 java
NAME                  DESCRIPTION                           STARS   OFFICIAL   AUTOMATED
java                  Java is a concurrent, class-based...   1037    [OK]       
anapsix/alpine-java   Oracle Java 8 (and 7) with GLIBC ...   115                [OK]
develar/java                                                 46                 [OK]
isuper/java-oracle    This repository contains all java...   38                 [OK]
lwieske/java-8        Oracle Java 8 Container - Full + ...   27                 [OK]
nimmis/java-centos    This is docker images of CentOS 7...   13                 [OK]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><p>参数说明：</p> <ul><li>NAME: 镜像仓库源的名称</li> <li>DESCRIPTION: 镜像的描述</li> <li>OFFICIAL: 是否 docker 官方发布</li> <li>stars: 类似 Github 里面的 star，表示点赞、喜欢的意思。</li> <li>AUTOMATED: 自动构建。</li></ul> <h2 id="本地镜像管理"><a href="#本地镜像管理" class="header-anchor">#</a> 本地镜像管理</h2> <h3 id="images"><a href="#images" class="header-anchor">#</a> images</h3> <p>docker images : 列出本地镜像。</p> <h4 id="语法-24"><a href="#语法-24" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker images [OPTIONS] [REPOSITORY[:TAG]]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-16"><a href="#options说明-16" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-a :列出本地所有的镜像（含中间映像层，默认情况下，过滤掉中间映像层）；</li> <li>--digests :显示镜像的摘要信息；</li> <li>-f :显示满足条件的镜像；</li> <li>--format :指定返回值的模板文件；</li> <li>--no-trunc :显示完整的镜像信息；</li> <li>-q :只显示镜像ID。</li></ul> <h4 id="实例-24"><a href="#实例-24" class="header-anchor">#</a> 实例</h4> <p>查看本地镜像列表。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker images
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>列出本地镜像中REPOSITORY为ubuntu的镜像列表。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker images  ubuntu
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="rmi"><a href="#rmi" class="header-anchor">#</a> rmi</h3> <p>docker rmi : 删除本地一个或多个镜像。</p> <h4 id="语法-25"><a href="#语法-25" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rmi [OPTIONS] IMAGE [IMAGE...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-17"><a href="#options说明-17" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-f :强制删除；</li> <li>--no-prune :不移除该镜像的过程镜像，默认移除；</li></ul> <h4 id="实例-25"><a href="#实例-25" class="header-anchor">#</a> 实例</h4> <p>强制删除本地镜像 ubuntu:v4。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rmi -f ubuntu:v4
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>删除所有未打 dangling 标签的镜像</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rmi $(docker images -q -f dangling=true)
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>通过镜像的id来删除指定镜像</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rmi &lt;image id&gt;
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>删除所有镜像</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker rmi $(docker images -q)
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="tag"><a href="#tag" class="header-anchor">#</a> tag</h3> <p>docker tag : 标记本地镜像，将其归入某一仓库。</p> <h4 id="语法-26"><a href="#语法-26" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker tag [OPTIONS] IMAGE[:TAG] [REGISTRYHOST/][USERNAME/]NAME[:TAG]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="实例-26"><a href="#实例-26" class="header-anchor">#</a> 实例</h4> <p>将镜像ubuntu:15.10标记为 ubuntu:v3 镜像。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker tag ubuntu:15.10 ubuntu:v3
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="build"><a href="#build" class="header-anchor">#</a> build</h3> <p>docker build 命令用于使用 Dockerfile 创建镜像。</p> <h4 id="语法-27"><a href="#语法-27" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker build [OPTIONS] PATH | URL | -
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-18"><a href="#options说明-18" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>--build-arg=[] :设置镜像创建时的变量；</li> <li>--cpu-shares :设置 cpu 使用权重；</li> <li>--cpu-period :限制 CPU CFS周期；</li> <li>--cpu-quota :限制 CPU CFS配额；</li> <li>--cpuset-cpus :指定使用的CPU id；</li> <li>--cpuset-mems :指定使用的内存 id；</li> <li>--disable-content-trust :忽略校验，默认开启；</li> <li>-f :指定要使用的Dockerfile路径；</li> <li>--force-rm :设置镜像过程中删除中间容器；</li> <li>--isolation :使用容器隔离技术；</li> <li>--label=[] :设置镜像使用的元数据；</li> <li>-m :设置内存最大值；</li> <li>--memory-swap :设置Swap的最大值为内存+swap，&quot;-1&quot;表示不限swap；</li> <li>--no-cache :创建镜像的过程不使用缓存；</li> <li>--pull :尝试去更新镜像的新版本；</li> <li>--quiet, -q :安静模式，成功后只输出镜像 ID；</li> <li>--rm :设置镜像成功后删除中间容器；</li> <li>--shm-size :设置/dev/shm的大小，默认值是64M；</li> <li>--ulimit :Ulimit配置。</li> <li>--squash :将 Dockerfile 中所有的操作压缩为一层。</li> <li>--tag, -t: 镜像的名字及标签，通常 name:tag 或者 name 格式；可以在一次构建中为一个镜像设置多个标签。</li> <li>--network: 默认 default。在构建期间设置RUN指令的网络模式</li></ul> <h4 id="实例-27"><a href="#实例-27" class="header-anchor">#</a> 实例</h4> <p>使用当前目录的 Dockerfile 创建镜像，标签为 lzpeng723/blog:v1。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker build -t lzpeng723/blog:v1 . 
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>使用URL github.com/creack/docker-firefox 的 Dockerfile 创建镜像。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker build github.com/creack/docker-firefox
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>也可以通过 -f Dockerfile 文件的位置：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker build -f /path/to/a/Dockerfile .
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>在 Docker 守护进程执行 Dockerfile 中的指令前，首先会对 Dockerfile 进行语法检查，有语法错误时会返回：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker build -t test/myapp .
Sending build context to Docker daemon 2.048 kB
Error response from daemon: Unknown instruction: RUNCMD
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h3 id="history"><a href="#history" class="header-anchor">#</a> history</h3> <p>docker history : 查看指定镜像的创建历史。</p> <h4 id="语法-28"><a href="#语法-28" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker history [OPTIONS] IMAGE
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-19"><a href="#options说明-19" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-H :以可读的格式打印镜像大小和日期，默认为true；</li> <li>--no-trunc :显示完整的提交记录；</li> <li>-q :仅列出提交记录ID。</li></ul> <h4 id="实例-28"><a href="#实例-28" class="header-anchor">#</a> 实例</h4> <p>查看本地镜像ubuntu:v3的创建历史。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker history ubuntu:v3
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="save"><a href="#save" class="header-anchor">#</a> save</h3> <p>docker save : 将指定镜像保存成 tar 归档文件。</p> <h4 id="语法-29"><a href="#语法-29" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker save [OPTIONS] IMAGE [IMAGE...]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options-说明"><a href="#options-说明" class="header-anchor">#</a> OPTIONS 说明：</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>-o :输出到的文件。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="实例-29"><a href="#实例-29" class="header-anchor">#</a> 实例</h4> <p>将镜像 mynginx 生成 mynginx.tar 文档</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker save -o mynginx.tar mynginx
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="load"><a href="#load" class="header-anchor">#</a> load</h3> <p>docker load : 导入使用 <a href="#save">docker save</a> 命令导出的镜像。</p> <h4 id="语法-30"><a href="#语法-30" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker load [OPTIONS]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options-说明-2"><a href="#options-说明-2" class="header-anchor">#</a> OPTIONS 说明：</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>--input , -i : 指定导入的文件，代替 STDIN。

--quiet , -q : 精简输出信息。
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><h4 id="实例-30"><a href="#实例-30" class="header-anchor">#</a> 实例</h4> <p>导入镜像：</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker load &lt; busybox.tar.gz
docker load --input fedora.tar
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div><h3 id="import"><a href="#import" class="header-anchor">#</a> import</h3> <p>docker import : 从归档文件中创建镜像。</p> <h4 id="语法-31"><a href="#语法-31" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-20"><a href="#options说明-20" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-c :应用docker 指令创建镜像；</li> <li>-m :提交时的说明文字；</li></ul> <h4 id="实例-31"><a href="#实例-31" class="header-anchor">#</a> 实例</h4> <p>从镜像归档文件mynginx.tar创建镜像，命名为mynginx:v4</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker import  mynginx.tar mynginx:v4  
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h2 id="info-version"><a href="#info-version" class="header-anchor">#</a> info|version</h2> <h3 id="info"><a href="#info" class="header-anchor">#</a> info</h3> <p>docker info : 显示 Docker 系统信息，包括镜像和容器数。。</p> <h4 id="语法-32"><a href="#语法-32" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker info [OPTIONS]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="实例-32"><a href="#实例-32" class="header-anchor">#</a> 实例</h4> <p>查看docker系统信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker info
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h3 id="version"><a href="#version" class="header-anchor">#</a> version</h3> <p>docker version :显示 Docker 版本信息。</p> <h4 id="语法-33"><a href="#语法-33" class="header-anchor">#</a> 语法</h4> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker version [OPTIONS]
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><h4 id="options说明-21"><a href="#options说明-21" class="header-anchor">#</a> OPTIONS说明：</h4> <ul><li>-f :指定返回值的模板文件。</li></ul> <h4 id="实例-33"><a href="#实例-33" class="header-anchor">#</a> 实例</h4> <p>显示 Docker 版本信息。</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>docker version
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div></div></section> <footer class="page-edit"><!----> <div class="last-updated"><span class="prefix">Last Updated: </span> <span class="time">1/28/2022, 8:09:41 AM</span></div></footer> <!----> <div class="comments-wrapper"><!----></div> <ul class="side-bar sub-sidebar-wrapper" style="width:12rem;" data-v-70334359><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-command.html#容器生命周期管理" class="sidebar-link reco-side-容器生命周期管理" data-v-70334359>容器生命周期管理</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#run" class="sidebar-link reco-side-run" data-v-70334359>run</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#start-stop-restart" class="sidebar-link reco-side-start-stop-restart" data-v-70334359>start/stop/restart</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#kill" class="sidebar-link reco-side-kill" data-v-70334359>kill</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#rm" class="sidebar-link reco-side-rm" data-v-70334359>rm</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#pause-unpause" class="sidebar-link reco-side-pause-unpause" data-v-70334359>pause/unpause</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#create" class="sidebar-link reco-side-create" data-v-70334359>create</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#exec" class="sidebar-link reco-side-exec" data-v-70334359>exec</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-command.html#容器操作" class="sidebar-link reco-side-容器操作" data-v-70334359>容器操作</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#ps" class="sidebar-link reco-side-ps" data-v-70334359>ps</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#inspect" class="sidebar-link reco-side-inspect" data-v-70334359>inspect</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#top" class="sidebar-link reco-side-top" data-v-70334359>top</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#attach" class="sidebar-link reco-side-attach" data-v-70334359>attach</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#events" class="sidebar-link reco-side-events" data-v-70334359>events</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#logs" class="sidebar-link reco-side-logs" data-v-70334359>logs</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#wait" class="sidebar-link reco-side-wait" data-v-70334359>wait</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#export" class="sidebar-link reco-side-export" data-v-70334359>export</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#port" class="sidebar-link reco-side-port" data-v-70334359>port</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-command.html#容器rootfs命令" class="sidebar-link reco-side-容器rootfs命令" data-v-70334359>容器rootfs命令</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#commit" class="sidebar-link reco-side-commit" data-v-70334359>commit</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#cp" class="sidebar-link reco-side-cp" data-v-70334359>cp</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#diff" class="sidebar-link reco-side-diff" data-v-70334359>diff</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-command.html#镜像仓库" class="sidebar-link reco-side-镜像仓库" data-v-70334359>镜像仓库</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#login" class="sidebar-link reco-side-login" data-v-70334359>login</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#pull" class="sidebar-link reco-side-pull" data-v-70334359>pull</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#push" class="sidebar-link reco-side-push" data-v-70334359>push</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#search" class="sidebar-link reco-side-search" data-v-70334359>search</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-command.html#本地镜像管理" class="sidebar-link reco-side-本地镜像管理" data-v-70334359>本地镜像管理</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#images" class="sidebar-link reco-side-images" data-v-70334359>images</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#rmi" class="sidebar-link reco-side-rmi" data-v-70334359>rmi</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#tag" class="sidebar-link reco-side-tag" data-v-70334359>tag</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#build" class="sidebar-link reco-side-build" data-v-70334359>build</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#history" class="sidebar-link reco-side-history" data-v-70334359>history</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#save" class="sidebar-link reco-side-save" data-v-70334359>save</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#load" class="sidebar-link reco-side-load" data-v-70334359>load</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#import" class="sidebar-link reco-side-import" data-v-70334359>import</a></li><li class="level-2" data-v-70334359><a href="/blogs/Docker/docker-command.html#info-version" class="sidebar-link reco-side-info-version" data-v-70334359>info|version</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#info" class="sidebar-link reco-side-info" data-v-70334359>info</a></li><li class="level-3" data-v-70334359><a href="/blogs/Docker/docker-command.html#version" class="sidebar-link reco-side-version" data-v-70334359>version</a></li></ul></main> <!----></div></div></div></div><div class="global-ui"><div class="back-to-ceiling" style="right:1rem;bottom:6rem;width:2.5rem;height:2.5rem;border-radius:.25rem;line-height:2.5rem;display:none;" data-v-c6073ba8 data-v-c6073ba8><svg t="1574745035067" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5404" class="icon" data-v-c6073ba8><path d="M526.60727968 10.90185116a27.675 27.675 0 0 0-29.21455937 0c-131.36607665 82.28402758-218.69155461 228.01873535-218.69155402 394.07834331a462.20625001 462.20625001 0 0 0 5.36959153 69.94390903c1.00431239 6.55289093-0.34802892 13.13561351-3.76865779 18.80351572-32.63518765 54.11355614-51.75690182 118.55860487-51.7569018 187.94566865a371.06718723 371.06718723 0 0 0 11.50484808 91.98906777c6.53300375 25.50556257 41.68394495 28.14064038 52.69160883 4.22606766 17.37162448-37.73630017 42.14135425-72.50938081 72.80769204-103.21549295 2.18761121 3.04276886 4.15646224 6.24463696 6.40373557 9.22774369a1871.4375 1871.4375 0 0 0 140.04691725 5.34970492 1866.36093723 1866.36093723 0 0 0 140.04691723-5.34970492c2.24727335-2.98310674 4.21612437-6.18497483 6.3937923-9.2178004 30.66633723 30.70611158 55.4360664 65.4791928 72.80769147 103.21549355 11.00766384 23.91457269 46.15860503 21.27949489 52.69160879-4.22606768a371.15156223 371.15156223 0 0 0 11.514792-91.99901164c0-69.36717486-19.13165746-133.82216804-51.75690182-187.92578088-3.42062944-5.66790279-4.76302748-12.26056868-3.76865837-18.80351632a462.20625001 462.20625001 0 0 0 5.36959269-69.943909c-0.00994388-166.08943902-87.32547796-311.81420293-218.6915546-394.09823051zM605.93803103 357.87693858a93.93749974 93.93749974 0 1 1-187.89594924 6.1e-7 93.93749974 93.93749974 0 0 1 187.89594924-6.1e-7z" p-id="5405" data-v-c6073ba8></path><path d="M429.50777625 765.63860547C429.50777625 803.39355007 466.44236686 1000.39046097 512.00932183 1000.39046097c45.56695499 0 82.4922232-197.00623328 82.5015456-234.7518555 0-37.75494459-36.9345906-68.35043303-82.4922232-68.34111062-45.57627738-0.00932239-82.52019037 30.59548842-82.51086798 68.34111062z" p-id="5406" data-v-c6073ba8></path></svg></div><div class="reco-bgm-panel" data-v-b1d3339e><audio id="bgm" src="/music/1.m4a" data-v-b1d3339e></audio> <div class="reco-float-box" style="bottom:200px;z-index:999999;display:none;" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><img src="https://y.qq.com/music/photo_new/T002R300x300M0000046Etze42qCxC_1.jpg" data-v-b1d3339e></div> <div class="reco-bgm-box" style="left:10px;bottom:10px;z-index:999999;" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><div class="reco-bgm-cover" style="background-image:url(https://y.qq.com/music/photo_new/T002R300x300M0000046Etze42qCxC_1.jpg);" data-v-b1d3339e><div class="mini-operation" style="display:none;" data-v-b1d3339e><i class="reco-bgm reco-bgm-pause" style="display:none;" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-play" style="display:none;" data-v-b1d3339e></i></div> <div class="falut-message" style="display:none;" data-v-b1d3339e>
          播放失败
        </div></div> <div class="reco-bgm-info" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><div class="info-box" data-v-b1d3339e><i class="reco-bgm reco-bgm-music music" data-v-b1d3339e></i>苍穹</div> <div class="info-box" data-v-b1d3339e><i class="reco-bgm reco-bgm-artist" data-v-b1d3339e></i>韩磊</div> <div class="reco-bgm-progress" data-v-b1d3339e><div class="progress-bar" data-v-b1d3339e><div class="bar" data-v-b1d3339e></div></div></div> <div class="reco-bgm-operation" data-v-b1d3339e><i class="reco-bgm reco-bgm-last last" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-pause pause" style="display:none;" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-play play" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-next next" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-volume1 volume" data-v-b1d3339e></i> <i class="reco-bgm reco-bgm-mute mute" style="display:none;" data-v-b1d3339e></i> <div class="volume-bar" data-v-b1d3339e><div class="bar" data-v-b1d3339e></div></div></div></div> <div class="reco-bgm-left-box" data-v-b1d3339e data-v-41bcba48 data-v-b1d3339e><i class="reco-bgm reco-bgm-left" data-v-b1d3339e></i></div></div></div><!----></div></div>
    <script src="/assets/js/app.b9ccfc55.js" defer></script><script src="/assets/js/4.8390fbcb.js" defer></script><script src="/assets/js/1.3334f995.js" defer></script><script src="/assets/js/33.2dcc611d.js" defer></script>
  </body>
</html>
